@extends('admin.admin')
@section('content-header')
    {{--<h1>--}}
        {{--用户管理--}}
        {{--<small>个人资料</small>--}}
    {{--</h1>--}}
    {{--<ol class="breadcrumb">--}}
        {{--<li><a href="{{url('/dashboard')}}"><i class="fa fa-dashboard"></i> 主页</a></li>--}}
        {{--<li class="active"><a href="{{url('/admin/info/index')}}">用户管理 - 个人资料</a></li>--}}
    {{--</ol>--}}
@stop

@section('content')
    <div class="panel">
        <div class="panel-body">
            <table id="demo-foo-filtering" class="table table-bordered table-hover toggle-circle" data-page-size="7">
                <div class="pad-btm form-inline" style="margin-bottom: 10px;">
                    <div class="row">
                        <div class="col-sm-6 text-xs-center" id='element_id'>
                            {{--<form action="{{ route('admin.school.index') }}" method="post">--}}
                            <form action="{{ url('admin/aduser/index') }}" method="post">
                                {{csrf_field()}}
                                {{--<input type="hidden" name="_method" value="get">--}}
                                <div class="form-group">
                                    <input id="demo-foo-search" type="text" placeholder="管理员搜索" class="form-control"
                                           autocomplete="off" name="name" value="{{$search['name'] or ''}}">
                                </div>
                                &nbsp;&nbsp;&nbsp;
                                <button class="btn btn-primary">搜索</button>
                                <a class="btn btn-primary" href="{{ url('admin/aduser/index') }}">清空查询</a>
                            </form>
                        </div>

                        <div class="col-md-6 text-right">
                            <a href="{{ url('admin/aduser/add') }}" class="btn btn-success btn-md"><i class="fa fa-plus-circle"></i> 添加会员 </a>
                        </div>
                    </div>
                </div>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>账号</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $k => $v)
                    <tr class="tr" data-cid="{{$v->uid}}">
                        <td>{{$v->id}}</td>
                        <td>{{ $v->username }}</td>
                        <td>
                            <a style="margin:3px;" href="{{ url('admin/aduser/edit').'/'.$v->id }}" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>
                            <a style="margin:3px;" href="#" data-id="{{$v->id}}" class="delBtn X-Small btn-xs text-danger "><i class="fa fa-times-circle-o"></i> 删除</a>
                        </td>
                    </tr>
                @endforeach

                </tbody>
                <tfoot>
                <tr>
                    <td colspan="5">
                        <div class="text-right">
                            {!! $data->appends(['name' => $search['name']])->render() !!}
                        </div>
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>

    </div>
    <div class="modal fade" id="modal-delete" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这个用户吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="{{ url('admin/aduser/delete') }}">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>

@stop

@section('script')
    <script>
        //删除
        $(document).on('click', '.delete', function () {
            var id = $(this).data('id');
            swal({
                title: "您确定要删除吗",
                text: "请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "red",
                confirmButtonText: "删除",
                cancelButtonText: "取消",
                closeOnConfirm: false
            }, function () {
                var urls = "{{ url('admin/aduser/delete') }}";
                $.get(urls, {id: id}, function (data) {
                    var data = eval("(" + data + ")");
                    console.log(data);
                    if (data.code == '0') {
                        swal("更新成功！", data.message, "success");
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    } else {
                        swal("更新失败！", data.message, "error");
                    }

                });
            });
        });

        $("table").delegate('.delBtn', 'click', function () {
            var id = $(this).data('id');
            $('.deleteForm').attr('action', '/admin/aduser/delete/' + id);
            $("#modal-delete").modal();
        });
    </script>

@stop

